package ru.spb.osll.myfit.server.parser;

import junit.framework.TestCase;
import org.junit.Test;
import ru.spb.osll.myfit.common.Page;
import ru.spb.osll.myfit.common.PageTag;

import java.util.*;

/**
 * User: Artem Bukhonov
 * Date: 24.02.12
 * Time: 18:15
 */
public class MetadataParserTest extends TestCase {
  private List<String> m_lines = new ArrayList<String>() {{
    add("myfit_page_tags=tag1,tag2,tag with space");
  }};
  
  private Set<PageTag> m_expectedTags = new TreeSet<PageTag>() {{
    add(new PageTag("tag1"));
    add(new PageTag("tag2"));
    add(new PageTag("tag with space"));
  }};
  private MetadataParser m_parser = new MetadataParser();

  public void testParseMetadata() throws Exception {
    Page page = new Page();
    page.setTags(m_parser.parseMetadata(m_lines));
    List<PageTag> act = new ArrayList<PageTag>(page.getTags());
    List<PageTag> exp = new ArrayList<PageTag>(m_expectedTags);
    Collections.sort(act);
    Collections.sort(exp);
    assertEquals(m_expectedTags.size(), page.getTags().size());
    for (int i = 0; i < act.size(); ++i) {
      assertEquals(exp.get(i).getString(), act.get(i).getString());
    }
  }
}
